package com.huluobo.module_test_agency.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.huluobo.appbase.network.HttpErrorDeal
import com.huluobo.module_test_agency.repo.AgencyRepo
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow

/**
 * Created by lc on 2022/12/29.
 * 检测机构的ViewModel
 */
class AgencyViewModel : ViewModel() {
    fun loadTestAgencyMessage(cityId: String) = flow {
        val data = AgencyRepo().loadTestAgencyMessage(cityId)
        emit(data)
    }.catch {
        if (it is Exception) {
            HttpErrorDeal.dealHttpError(it)
        }
        emit(null)
    }.asLiveData()
}